package 滑动窗口;

/**
 * @author: yangwk
 * @date: 2023/4/21
 * @description:
 **/
public class 统计01 {
    public static void main(String[] args) {
        System.out.println(statistic("00011100"));
    }

    public static int statistic(String str) {
        int count = 0;
        int maxLength = str.length() / 2;
        for (int i = 0; i < str.length(); i++) {
            for (int j = 1; j < maxLength && i + j * 2 <= str.length(); j++) {
                String substring = str.substring(i, i + j * 2);
                if (find(substring)) {
                    System.out.println(substring);
                    count++;
                }
            }
        }
        return count;
    }

    private static boolean find(String substring) {
        int length = substring.length();
        char pre = substring.charAt(0);
        int preNum = 1, nextNum = 0;
        for (int i = 1; i < length; i++) {
            if (substring.charAt(i) == pre) {
                preNum++;
            } else {
                if (nextNum != 0) {
                    return false;
                }
                pre = substring.charAt(i);
                nextNum = preNum;
                preNum = 1;
            }
        }
        return nextNum == preNum;
    }
}
